//
//  SGQCodeViewController.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/10/22.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "SGQCodeViewController.h"

#import "SGQRCodeGenerateManager.h"
@interface SGQCodeViewController ()

@end

@implementation SGQCodeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self showNav:@"我的邀请码"];
    self.view.backgroundColor = COLOR_RGB(242, 242, 242, 1);
    
    NSString *aaa = [NSString stringWithFormat:@"%@/merchants.php/Home/Login/agencyApply/identify/ydd/from/app/invitecode/%@.html",urlHead,_str];
    NSLog(@"aaa:%@",aaa);
    [self setupGenerateQRCode:aaa];
    
}

// 生成二维码
- (void)setupGenerateQRCode:(NSString *) strcode{
    
    // 1、借助UIImageView显示二维码
    UIImageView *imageView = [[UIImageView alloc] init];
    CGFloat imageViewW = 150;
    CGFloat imageViewH = imageViewW;
    CGFloat imageViewX = (self.view.frame.size.width - imageViewW) / 2;
    CGFloat imageViewY = 80;
    imageView.frame =CGRectMake(imageViewX, imageViewY, imageViewW, imageViewH);
    [self.view addSubview:imageView];
    
    // 2、将CIImage转换成UIImage，并放大显示
    imageView.image = [SGQRCodeGenerateManager generateWithDefaultQRCodeData:strcode imageViewWidth:imageViewW];
    
#pragma mark - - - 模仿支付宝二维码样式（添加用户头像）
    CGFloat scale = 0.22;
    CGFloat borderW = 5;
    UIView *borderView = [[UIView alloc] init];
    CGFloat borderViewW = imageViewW * scale;
    CGFloat borderViewH = imageViewH * scale;
    CGFloat borderViewX = 0.5 * (imageViewW - borderViewW);
    CGFloat borderViewY = 0.5 * (imageViewH - borderViewH);
    borderView.frame = CGRectMake(borderViewX, borderViewY, borderViewW, borderViewH);
    borderView.layer.borderWidth = borderW;
    borderView.layer.borderColor = [UIColor purpleColor].CGColor;
    borderView.layer.cornerRadius = 10;
    borderView.layer.masksToBounds = YES;
    borderView.layer.contents = (id)[UIImage imageNamed:@"logo"].CGImage;
    
    //[imageView addSubview:borderView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
